<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport"
	content="width=device-width,initial-scale=1.0,user-scalable=no" />
<title>确认订单</title>
<link rel="stylesheet" href="<%=basePath%>assets/css/reset.css">
<link rel="stylesheet" href="<%=basePath%>assets/css/page.css">
<script src="<%=basePath%>assets/js/jquery-2.1.1.min.js"></script>
<script src="<%=basePath%>assets/js/page.js"></script>
<link rel="stylesheet" href="<%=basePath%>assets/css/public.css">
<link rel="stylesheet"
	href="<%=basePath%>assets/font-awesome-4.7.0/css/font-awesome.min.css">
<script src="<%=basePath%>assets/js/fontSize.js"></script>
<link href="<%=basePath%>/assets/layer/mobile/need/layer.css"
	rel="stylesheet" type="text/css">
<script src="<%=basePath%>/assets/layer/mobile/layer.js"></script>

<style type="text/css">
.biaotitianxie {
	border: none;
	height: 2.8rem;
	line-height: 1.8rem;
	width: 90%;
	margin: 5px 5%;
	border-bottom: 1px solid #f1f1f1;
	font-size: 1.2rem
}

.order>li>.order_list1>.content>span {
	line-height: 0.3rem;
}

.order>li>.order_list1>.content>a>p {
	line-height: 0.3rem;
}

.order>li>.order_list1>.content>a>.goodsSize {
	margin-top: 0.6rem;
	font-size: 0.18rem;
	color: #9e8686;
}


.shopping_bar2 {
	bottom: 0
}

.shouhuodizhi {
	width: 100%;
	background: #fff;
	margin-top: 0.8rem;
	padding-top: 8px;
}

.dwIcon {
	width: 12%;
	text-align: left;
	font-size: 0.4rem;
}

.dwIcon i {
	margin-left: 0.2rem;
}

.shouhuodizhi_xq {
	width: 75%;
	height: 1.2rem
}

.shouhuorenxinxi span {
	font-size: 0.28rem;
	height: 0.6rem;
	line-height: 0.6rem;
}

.tiaozhuan {
	width: 13%;
	font-size: 0.4rem;
	text-align: right;
}

.tiaozhuan i{
	margin-right: 0.2rem;
}

.tiaozhuan a {
	display: block;
	line-height: 1.4rem;
	font-size: 0.4rem;
	text-align: center
}

.xingxidizhi {
	font-size: 0.22rem;
	line-height: 0.3rem;
}
</style>
</head>
<body>
	<input id="basePath" type="hidden" value="<%=basePath%>">
	<div class="header">
		<a class="returnInfo" href="#" onclick="javascript:history.go(-1);"><i class="fa fa-angle-left"></i></a> 确认订单
	</div>
	<c:if test="${personDefaultAddress ne null}">
		<div class="shouhuodizhi clearFirx border-bottom-8" onclick="toSelectAddress()">
			<div class="dwIcon float_l">
				<i class="fa fa-map-marker"></i>
			</div>
			<div class="shouhuodizhi_xq float_l">
				<p class="shouhuorenxinxi clearFirx">
					<span class="shrxingming float_l">收货人：${personDefaultAddress.userName}</span><span
						class="shrdianhua float_r">${personDefaultAddress.userPhone}</span>
				</p>
				<p class="xingxidizhi">收货地址：${personDefaultAddress.province}${personDefaultAddress.city}${personDefaultAddress.county}${personDefaultAddress.address}</p>
			</div>
			<div class="tiaozhuan float_l">
				<i class="fa fa-angle-right"></i>
			</div>
		</div>
	</c:if>
	<c:if test="${personDefaultAddress eq null}">
		<div class="shouhuodizhi clearFirx border-bottom-8" onclick="toAddAddress()">
			<div class="dwIcon float_l">
			</div>
			<div class="shouhuodizhi_xq float_l" style="text-align: center;width: 100%;">
				<p class="shouhuorenxinxi clearFirx" >
					<span class="shrdianhua" style="line-height: 1.0rem;font-size: 0.32rem;">+</span>&emsp;<span class="shrdianhua" style="line-height: 1.0rem;font-size: 0.32rem;">新建收货地址</span>
				</p>
			</div>
		</div>
	</c:if>
	<ul class="order" id="goods">
		<li>
			<div class="order_list1">
				<div class="content">
					<a href="#"> <input id="goodsId" value="${goods.goodsId}" type="hidden" /> 
						<img src="<%=basePath%>/app/getGoodsPhotoByName?goodsImage=${goods.goodsThums}" alt="">
							<p class="goodsName">${goods.goodsName}</p>
							<c:if test="${not empty goodsSize}">
								<p class="goodsSize">规格：${goodsSize}</p>
							</c:if>
					</a> 
					<span>
						<i class="fa fa-rmb"></i>${goods.goodsPrice}
						<em>x${orderCount}</em>
					</span>
				</div>
			</div>
		</li>
	</ul>

	<div class="shopping_bar2" style="font-size: 16px">
		<p style="padding-left: 10px;">
			总金额<span id="total_price"></span> <em style="color: red">￥${unitPriceTotal}</em>
		</p>
		<a href="#" id="btn">提交订单</a>
	</div>
</body>
<script type="text/javascript">
	$('.order').find('li .order_list1').each(function(){
		var goodsNameHtml = $(this).find('.goodsName').html();
		$(this).find('.goodsName').html(showText(goodsNameHtml, 31))		
	})
	$("#btn").click(function(){
		var personDefaultAddress='${personDefaultAddress}'
		if(personDefaultAddress==null||personDefaultAddress==''){
			layer.open({
  			    content: '请添加收货地址'
  			    ,skin: 'msg'
  			    ,time: 2 //2秒后自动关闭
  			})
			return;
		}
// 		var goodsCount = '${orderCount}';
// 		var userName = '${personDefaultAddress.userName}';
// 		var userPhone = '${personDefaultAddress.userPhone}';
// 		var province = '${personDefaultAddress.province}'+'${personDefaultAddress.city}'+'${personDefaultAddress.county}'+'${personDefaultAddress.address}';
		$.ajax({
			url: $("#basePath").val()+"app/directOrder",
		    timeout: 300000,
		    dataType: "json",
		    type: "post",
		    data: {
		    	"goodsId":$("#goodsId").val(),
		    	"goodsCount":'${orderCount}',
		    	"userName":'${personDefaultAddress.userName}',
		    	"userPhone":'${personDefaultAddress.userPhone}',
		    	"userAddress":'${personDefaultAddress.province}'+'${personDefaultAddress.city}'+'${personDefaultAddress.county}'+'${personDefaultAddress.address}',
		    	"goodsSize":'${goodsSize}'
		    },success: function (data) {
		    	window.location.href = $("#basePath").val()+"app/getUserOrderList";
	        },error: function (data) {
	        	layer.open({
      			    content: '网络有点延迟，客官请稍等～'
      			    ,skin: 'msg'
      			    ,time: 2 //2秒后自动关闭
      			  });
	        }
		})
	})
	//选择订单地址
	function toSelectAddress(){
		var goodsIdNum = '${goods.goodsId}';
		var goodsThumsNum = '${orderCount}';
		window.location.href="<%=basePath%>app/toSelectAddress?state=2&goodsIdNum="+ goodsIdNum + "&goodsThumsNum=" + goodsThumsNum;
	};
	function showText(text, numSub) {
		if (text == null) {
			return "";
		}
		if (text.length > numSub) {
			return text.substring(0, numSub) + "...";
		}
		return text;
	}
	//跳新增地址
	function toAddAddress(){
		window.location.href="<%=basePath%>jsp/app/addAddress.jsp";
	}
</script>
</html>